var path = require("path");
var dao = require(path.join(process.cwd(), "dao/DAO"));

/**
 * 更新是否有图
 * 
 * @param  {[type]} comment [评价对象]
 */
module.exports.doUpdateHasImg = function (comment) {
    return new Promise(function (resolve, reject) {
        if (comment.pics && Array.isArray(comment.pics)) {
            var has_img = comment.pics.length == 0 ? 0 : 1;
            dao.update("CommentModel", comment.id, {
                has_img: has_img
            }, function (err) {
                if (err) return reject({
                    msg: "更新评价信息失败！",
                    code: 500,
                    stack: err
                });
                comment.has_img = has_img;
                resolve(comment);
            });
        } else {
            resolve(comment)
        }
    });
}
